/*
#========================================================================
#
# Alan Rogers
# Massachusetts Institute of Technology Haystack Observatory
# Program: vlbi2
# Calculate cross or autocorrelation spectra from Mk5b recorded data.
#
# The vlbi2 program is used to correlate two Mark 5B files with the same
# starting record time and record mode. A postscript file dd1.pos is 
# produced showing the correlation amplitude and phase as a function
# of frequency in all channels in the two files with all channels 
# plotted on the same axes. Correlation coefficients (fringe amplitudes, 
# which will be 1.00 for an autocorrelation) are indicated below each 
# channel. The vlbi2 program accepts two files, each 10 MB in size, 
# and two flags. The usage is:
#
#        vlbi2 <file1> <file2> [-2bit <2bit_arg>] [-rev <rev_arg>]
#
# Where the items in [] are optional. The -2bit flag indicates whether
# the files are 2 bits/sample recordings (2bit_arg is 1) or 1 bit/sample
# (2bit_arg is 0) [default]. The files must be the same number of 
# bits per sample. The .rev flag determines whether the channels in dd1.pos
# are plotted in reverse order (rev_arg is 1) or normal order 
# (rev_arg is 0) [default]. It is important to note that with the .rev 
# flag, though the channels can be plotted in the reverse order, they 
# are not flipped in frequency. If file1 and file2 are the same, an 
# autocorrelation is produced; if they are different a cross correlation 
# is produced.
#
#
#=======================================================================
#
# Dec 2010
# S.Weston		stuart.weston@aut.ac.nz
# AUT University
#
# Modified to use DISLIN so that we can see the data better than just
# printed across the bottom of an A4 sheet in postscript. Also use
# DISLIN widgets to provide a better UI.
#
#=======================================================================
*/

#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include "vlbi2.h"


int main(int argc, char *argv[])
{
    char filenamein1[256], filenamein2[256], filenameout[256], buf[80];
    int proctime;
    int rev;
    int tbit;
    int i;
    double swidth;    
    double fwidth;

    proctime = 100;   // Number of frames to read and integrate over
    swidth = 3000;
    fwidth = 0;
    rev = 0;
    tbit = 0;
    verbose=0;

    printf("vlbi2 Version 2 Revision 0 - 8th Dec 2010\n");

    filenamein1[0]=filenamein2[0]=0;
    if(argc < 2) { 
      printf("vlbi22 file1 file2 -proctime proctime -rev rev -2bit 2bit\n");
      return 0;
     }
    if (argc > 1)
        sscanf(argv[1], "%255s", filenamein1);
    if (argc > 2)
        sscanf(argv[2], "%255s", filenamein2);

    for(i=0;i<argc;i++){
    sscanf(argv[i], "%79s",buf);
    if(strstr(buf, "-proctime")) sscanf(argv[i+1],"%d",&proctime);
    if(strstr(buf, "-rev")) sscanf(argv[i+1],"%d",&rev);
    if(strstr(buf, "-2bit")) sscanf(argv[i+1],"%d",&tbit);
    if(strstr(buf, "-v")) verbose=1;
     }

    printf("Verbose Mode = %d\n",verbose);
    process2(filenamein1,filenamein2, filenameout, proctime,swidth,fwidth,rev,tbit);

}


